<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>
        hello
    </title>
    <script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="js/jsonFormater.js"></script>
    <script type="text/javascript" src="js/json2.js"></script>
    <script type="text/javascript" src="js/security.js"></script>
    <link rel="stylesheet" href="js/jsonFormater.css">
    <script type="text/javascript">
	$(function(){
		$('#subt').click(function(){
				var name = jQuery('#loginName').val();
				var password =jQuery('#loginPwd').val();
				if(name==null||name==""){
					alert("用户名不得为空！");
					return;
				}
				if(password==null||password==""){
					alert("密码不得为空！");
					return;
				}
				var rd=getPublicKey();
                if(rd!=null){
                    //加密模
                    var Modulus = rd.split(';')[0];
                    //公钥指数
                    var public_exponent = rd.split(';')[1];
                    //通过模和公钥参数获取公钥
                    var key = new RSAUtils.getKeyPair(public_exponent, "", Modulus);
                    //颠倒密码的顺序，要不然后解密后会发现密码顺序是反的
                    var reversedPwd = password.split("").reverse().join("");
                    //对密码进行加密传输
                    var encrypedPwd = RSAUtils.encryptedString(key,reversedPwd);
                    login({"loginPwd":encrypedPwd,"loginName":name});
                }
		})


		$('#find').click(function(){
            var ret;
            var name = jQuery('#findName').val();
            var sort = jQuery('#sort').val();
		    jQuery.ajax({
				type:"GET",
				url:"user/sortAndFind/dsad",
				async: false,
				data : {"loginName":name,"sort":sort},
				success:function(data){
				        var options = {
							dom : '#container' //对应容器的css选择器
						};
						var jf = new JsonFormater(options); //创建对象
						jf.doFormat(data); //格式化json
				}
			})
		})


	})

	function login(data){
		var ret;
		jQuery.ajax({
				type:"post",
				url:"user/login",
				async: false,
				data : data,
				success:function(rd){
				     ret=rd;
				     alert(rd);
				}
			})
		return ret;
	}

	function getPublicKey(){
		var ret;
		jQuery.ajax({
				type:"Get",
				url:"user/getPublicKey",
				async: false,
				success:function(rd){
				     ret=rd;
				}
			})
		return ret;
	}


	</script>
</head>
<body>
用户名:<input type="text" id="loginName">
密 码 :<input type="text" id="loginPwd">
<input type="button" value="登录" id="subt">
<br>
<br>
----------------------登录名查找-------------------------
<br>
<br>

登录名 :<input type="text" id="findName">
排序 :
<select id="sort">
    <option value="id">id</option>
    <option value="loginname">loginname</option>
    <option value="" selected="true">不排序</option>
</select>
<input type="button" value="查找" id="find">
<div id="container"></div>
</body>
</html>